// pages/webSite/webSite.js
import { lgRequest } from '../../../utils/ajax'
import util from '../../../utils/util'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    markers:[],
    longitude:'',
    latitude:'',
    mapCtx:null,
    qqmapsdk:'',
    isShowsatellite:false,
    statusBarHeight: getApp().globalData.statusBarHeight,
    titleBarHeight: getApp().globalData.titleBarHeight,
    sysInfo:getApp().globalData.sysInfo,
    isIphoneX:getApp().globalData.isIphoneX,
    keyWords:'',
    selectIndex:null,
    selectItem:{},
    isSHowSelect:true,
    isShowAllSelect:false,
    showOrderList:false,
    isSelectDay:true,
    kanCha:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/b6de0df7915e37f465877bc3b84538b0.png',
    allOptioner:[
      {
        name: '全部',
        color: '#4E81F0 ',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/b5c09367ed670069b11a714bdc0662ed.png'
      },
      {
        name:'勘察',
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/b6de0df7915e37f465877bc3b84538b0.png',
        color:'#F6AF00'
      },
      {
        name: '施工',
        color: '#07A4EC',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/d373abf480d3dd63c93167e1d5d8df9f.png'
      },
      {
        name: '交付',
        color: '#029E47',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/889393f8e19de3c395ed864443ce3bc0.png'
      },
      {
        name: '故障',
        color:'#E80010 ',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/bfa4cb05bd3857577c233de7d84546f9.png'
      },
      {
        name: '拆除',
        color:'#FF6436',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/889f8ba152b99e2ea173389229423be1.png'
      },
      {
        name: '添加',
        color: '#08B7B3',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/320d933252c34b5684c1dc54c2e365f7.png'
      },
    ],
    orderList:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/7894a02b181e5dae677cf4acf3e74004.png',
    selectDay:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/2687ed8098204efb6c45e14962edbc04.png',
    noSelectDay:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/375e71461a9dec9dfd8ee5291e0a165c.png',
    selectSatellite:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/5cb83962ac8c2e8c5088b6132716f19c.png',
    nosSlectSate:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/137b7e067ee70b08a1207adbb91f4083.png',
    toMap:"https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/02/2b9df4d67b60bf2f9037e30cc3aa546f.png",
    scale:15,
    // 一级
    kanCha1:'http://114.115.190.196:8082/profile/upload/2022/08/25/a2280b3eba0880536b851327bc0e65b3.png',
    shiGong1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/9217f7ac015db312277e276c27e03915.png',
    chaiChu1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/1f261dd1234d54d2b7c6b5922a63db86.png',
    jiaoFu1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/b196b8010e9ca624bcdf199a2034b46b.png',
    guZhang1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/bf46e93d495244a5cdb0fa2347ad2398.png',
    // 二级
    kanCha2:'http://114.115.190.196:8082/profile/upload/2022/08/25/5551ea86329f37ad02fb088a60ed1631.png',
    shiGong2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/cf7cf5a8d89e831a4d0afe5fcd234912.png',
    chaiChu2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/e9ec7fbfc844e3ae993e9c0b77017fa5.png',
    jiaoFu2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/ccb995dfd70b91544cbe148a742dc37b.png',
    guZhang2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/1c20aa36563bcc2d7462772e6009c6d7.png',
    // 三级
    kanCha3:'http://114.115.190.196:8082/profile/upload/2022/08/25/cc101e4830b06e751d132b43e4a3687e.png',
    shiGong3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/b8f3d0d0a53ef54cfe10caf72776e001.png',
    chaiChu3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/8f9bced64babc568587e4d50dbe0d71f.png',
    jiaoFu3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/e9cf93b827b684ccaeb8b03dc4468715.png',
    guZhang3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/abcf853c5f9d5ecc75804f763673dbfc.png',
    rightImgIcon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/a13909155ea0aee23bb1d8dd0c6b38ca.png',
    shareImg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/20/7c16fe32f8ed3f1ce246225098693aa8.png',
    stateTypeList:[
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/813f165e0244282350faccd65113a0d7.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/57e4a7ac0ff81402611cef693a1837cc.png',
        name:'勘察',
        color:'#F9BF2E'
      },
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/29ac8f92f0a33c77b720160261e4061d.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/dac9690ffff6d31d3e738c0f508d4192.png',
        name:'施工',
        color:'#1A9CD9'
      },
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/7fbe3867eb3c5f7adc9ccf4e94e2e426.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/911916ae23a088df5eab5c97e2462928.png',
        name:'交付',
        color:'#16B76F'
      },
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/53a841f7313bf50da23769d88569518f.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/e21541592144017dd21965d8255d0b8e.png',
        name:'故障',
        color:'#E81826'
      },
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/eae8df44368eb5a6d193731952f145d1.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/9e9043e0cdb7f5db7b478d3958653204.png',
        name:'拆除',
        color:'#FD7E5D'
      },
      //加了状态  别忘记换
      {
        icon:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/eae8df44368eb5a6d193731952f145d1.png',
        icon_active:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/9e9043e0cdb7f5db7b478d3958653204.png',
        name:'停用',
        color:'#FD7E5D'
      },
    ],
    switchList:[
      {
        name:'未取电',
        name_active:'已取电',
        isSelect:false
      },
      {
        name:'未安装',
        name_active:'已安装',
        isSelect:false
      },
      {
        name:'未核电',
        name_active:'已核电',
        isSelect:false
      },
      {
        name:'未立杆',
        name_active:'已立杆',
        isSelect:false
      },
      {
        name:'未联网',
        name_active:'已联网',
        isSelect:false
      }
    ],
    orderType:[
      {
        valueName:"集成问题",
        id:"1",
        problemType:"集成",
        typeCode:1
      },
      {
        valueName:"设备问题",
        id:"2",
        problemType:"设备",
        typeCode:2
      },
      {
        valueName:"电力问题",
        id:"3",
        problemType:"网络",
        typeCode:3
      },
      {
        valueName:"网络问题",
        id:"4",
        problemType:"电力",
        typeCode:4
      }
    ],
    greenBg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png',
    whiteBg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/f37e1fe6501f44eb5fb877eff35068f2.png',
    circle:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/ac0b6544db4ed907bf5444fc888409aa.png',
    selectIndexType:'',
    parentList:[],
    childrenList:[],
    siteListData:[],
    keyWords:'',
    showPop:false,
    scrollTop:0,
    isShowBottom:false,
    showloactionInfo:false,
    showSecondlevel:false,
    clickItemPostion:{},
    selectTagItem:{},
    selectTagIndex:'',
    selectPackIfo:{}, //选中的分组信息
    markerInfo:{},
    orderListList:[],
    mapScale:10,
    clickItemInfo:{},
    isSelectSiteCondition:"j",
    selectSiteCondition:"",
    params:{},
    overPeople:"",
    
    isType:0,
    problemType : [],
  },
    // 查询站点状态施工进度
    constructionProgress() {
      let params = {
        siteId: this.data.clickItemPostion.id
      }
      console.log("123456", params)
      lgRequest("constructionProgress", params, {
        doSuccess: (r) => {
          console.log("施工状态", r)
          this.setData({
            switchList: r.data
          })
        }
      })
    },
  clickItem(e){
    console.log(e)
    this.setData({
      selectIndex: e.target.dataset.index,
      selectItem: e.target.dataset.item,
    })
    this.getChildrenList()
  },
  clickChildItem(e){
    let selectPackIfo = e.currentTarget.dataset.item
    this.setData({
      selectIndex: null,
      isSHowSelect:false,
      selectPackIfo:selectPackIfo,
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      selectChIndex: e.target.dataset.index,
    })
    this.siteList()
  },
  showisSHowSelect(){
    this.setData({
      selectIndex: null,
      isSHowSelect: !this.data.isSHowSelect,
    })
    // console.log(!this.data.isSHowSelect)
    // this.data.isSHowSelect=!this.data.isSHowSelect

  },
  clickTag(e){
    let tagName = this.data.tagName;
    let index =  e.target.dataset.index ;
    tagName[index].typeCode = !tagName[index].typeCode
    
    this.setData({
      tagNameIndex :  e.target.dataset.index ,
      tagName
    })
  },
  showAllSelect(e){
    this.siteList();
    let selectIndex = e.target.dataset.index;
    let OrderUrgency = this.data.OrderUrgency;
    OrderUrgency.forEach(item=>{
      item.isSelect = false
    })
    let orderType = this.data.orderType;
    orderType.forEach(item=>{
      item.isSelect = false
    })
    this.setData({
      // isShowAllSelect: !this.data.isShowAllSelect,
      selectTagItem:selectIndex?this.data.allOptioner[selectIndex]:{},
      selectTagIndex:selectIndex?selectIndex:'',
      OrderUrgency,
      orderType
    })
    if(selectIndex!=6){
      this.siteList()
    }
    switch (selectIndex){
      case 6:
        wx.navigateTo({
          url: '../minePage/addSite/addSite',
        })
        break;
    }
  },
  showOrderList(){
    this.setData({
      showOrderList: !this.data.showOrderList
    })
  },
  selectDayType(e){
    this.setData({
      isSelectDay: e.currentTarget.dataset.select
    })
  },
  rangeChange(e){
    let that = this
    this.data.mapCtx.getScale({
      success:function(res){
        that.setData({
          scale:res.scale
        })
      },
    })
  },
  /**
   * 点击标记点
   * @param {*} options 
   */
  async markerClick(e){
    
    console.log(e)
    // debugger
    let Mid = e.markerId
    this.setData({
      Mid
    })
    this.getOrderList(Mid)
    let clickItem1 = this.data.clickItem1
    // this.data.markers.forEach(r=>{
    //   if(r.id==Mid){
      
    //       clickItem1 = r
   
    //   }
    // })
    // clickItem1.list=clickItem1.list.split(":")
    //   this.setData({
    //     clickItem1
    //   })
    // let clickItem1 = this.data.markers[index]
    // console.log(index)
    // undoneInfoList
    let orderListList = this.data.orderListList
    orderListList.forEach(item=>{
      if(item.zid==Mid){
        this.setData({
          undoneInfoList:item
        })
      }
    })
    let clickItem = (this.data.markers.filter(item=>item.id==e.markerId))[0]
    let markers = this.data.markers
    markers.forEach(item=>{
      if(item.id==e.markerId){
        item.beforeiconPath = item.iconPath
        item.beforewidth = item.width;
        item.beforeheight = item.height;
        let iconPath = `${item.pathName}3`
        item.iconPath = this.data[iconPath]
        item.width = 29.5;
        item.height = 38;
      } else {
        if(item.beforeiconPath){
          item.iconPath = item.beforeiconPath
          item.width = item.beforewidth;
          item.height = item.beforeheight;
          delete item.beforeiconPath
          delete item.beforewidth
          delete item.beforeheight
        }
      }
    })
    let clickItemInfo = [];
    try{
      clickItemInfo = await this.picStateList(clickItem.id,clickItem.state)
      console.log(clickItemInfo,'clickItemInfo')
    }catch(err){

    }
    this.setData({
      markers,
      clickItemPostion:clickItem,
      clickItemInfo:clickItemInfo,
      showloactionInfo:true,
      // clickItem1
    })
    this.constructionProgress()
  },
  //获取站点图片
  picStateList(id,state){
    return new Promise((resolve,reject)=>{
      let params = {
        siteId:id,
        state:state,
      }
      lgRequest('picStateList', params, {
        errAlert: false,
        doSuccess: r => {
          if (r.code == 200) {
            resolve(r.data)
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
            reject()
          }
        },
        doComplete: r => {
        }
      })
    })
    
  },
  /**
   * 
   * 获取左侧列表信息} 
   */
  fList() {
    let params = {};
    lgRequest('fList', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200) {
          console.log(r.data.list)
          this.setData({
            parentList : r.data.list
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  /**
   * 
   * @param {获取子集列表} options 
   */
  getChildrenList(){
    let params = {
      fatherId:this.data.selectItem.id
    }
    lgRequest('packetList', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200) {
          this.setData({
            childrenList : r.data
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  // 工单紧急程度
  getOrderUrgency(){
    let params = {
      code : "order_level"
    }
    lgRequest("dictionaries",params,{
      doSuccess:r=>{
        console.log("工单紧急程度",r)
        this.setData({
          OrderUrgency:r.data
        })
      }
    })
  },
  /**
   * 站点信息
   */
  siteList(tag,states,urgent,type,conductors){
    
    if(tag||states||urgent||type||conductors){
      
      let params = {
        packetId:this.data.selectPackIfo.id?this.data.selectPackIfo.id:(this.data.selectItem.id?this.data.selectItem.id:''),
        tag,
        states,
        urgent:urgent?urgent:'',
        type:type?type:"",
        conductors:conductors?conductors:'',
      };
      console.log("mark参数",params)
      lgRequest('undoneList', params, {
        errAlert: false,
        doSuccess: r => {
          if (r.code == 200) {
            let markers = [];
            let flag = false
            if(this.data.markers.length>0){
              flag=true
              this.setData({
                markerInfo:this.data.markers[0]
              })
            } else {
              this.setData({
                mapScale:11
              })
            }
            r.data.forEach(item=>{
              if(item.state!=6){
                console.log('地图报错',item)
                item.tag = item.tag?item.tag.split(','):''
                let itemGps = item.gps?item.gps.split(','):''
                let itemInfo = item
                itemInfo = {
                  id:parseInt(item.zid),
                  longitude:itemGps[0]*1,
                  latitude:itemGps[1]*1,
                  address:item.address,
                  // iconPath:this.data.kanCha3,
                  name:item.name,
                  stateName:item.stateName,
                  stateIcon :item.state?this.data.stateTypeList[item.state-1].icon_active:'',
                  width:flag?this.data.markerInfo.width:'9',
                  height:flag?this.data.markerInfo.height:'9',
                  tag:item.tag,
                  state:item.state,
                  urgent: item.urgent,
                  userName:item.userName,
                  list:item.list,
                  conductor:item.conductor,
                  item:item
                }
                let iconPathInfo = this.changePathInfo(item)
                itemInfo.pathName = iconPathInfo.pathName
                itemInfo.iconPath = iconPathInfo.iconPath
                markers.push(itemInfo)
              }
            })
            this.setData({
              markers:markers,
              orderListList:r.data
            })
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
          }
        },
        doComplete: r => {
        }
      })
    }else{
      let params = {
        packetId:this.data.selectPackIfo.id?this.data.selectPackIfo.id:'',
        tag:this.data.selectTagIndex?this.data.selectTagIndex:''
      }
      lgRequest('undoneList', params, {
        errAlert: false,
        doSuccess: r => {
          console.log(r)
          if (r.code == 200) {
            let markers = [];
            let flag = false
            if(this.data.markers.length>0){
              flag=true
              this.setData({
                markerInfo:this.data.markers[0]
              })
            } else {
              this.setData({
                mapScale:11
              })
            }
            r.data.forEach(item=>{
              if(item.state!=6){
                console.log('地图报错',item)
                item.tag = item.tag?item.tag.split(','):''
                let itemGps = item.gps?item.gps.split(','):''
                let itemInfo = {
                  id:parseInt(item.zid),
                  longitude:itemGps[0]*1,
                  latitude:itemGps[1]*1,
                  address:item.address,
                  // iconPath:this.data.kanCha3,
                  name:item.name,
                  stateName:item.stateName,
                  stateIcon :item.state?this.data.stateTypeList[item.state-1].icon_active:'',
                  width:flag?this.data.markerInfo.width:'9',
                  height:flag?this.data.markerInfo.height:'9',
                  tag:item.tag,
                  state:item.state,
                  urgent: item.urgent,
                  userName:item.userName,
                  list:item.list,
                  conductor:item.conductor,
                }
                let iconPathInfo = this.changePathInfo(item)
                itemInfo.pathName = iconPathInfo.pathName
                itemInfo.iconPath = iconPathInfo.iconPath
                markers.push(itemInfo)
              }
            })
            this.setData({
              markers:markers,
              orderListList:r.data
            })
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
          }
        },
        doComplete: r => {
        }
      })
    };
    

 
  },
  // 获取站点分组信息
  getSite(){
    let Authorization = getApp().globalData.Authorization;
    let server = getApp().globalData.server;
    wx.request({
      url: `${server}server/dictionaries/site_state`,
      header:{
        Authorization
      },
      success:(r)=>{
        console.log(r)
        let siteCondition = r.data.data;
        let quanbu = {
          valueId:"0",
          valueName:'全部',
        };
        siteCondition.unshift(quanbu)
        this.setData({
          siteCondition
        })
      }
    })
  },
  // 修改站点分组信息
  selectSiteCondition(e){
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    let isSelectSiteCondition = index;
    let selectSiteCondition = item;
    this.setData({
      isSelectSiteCondition,
      selectSiteCondition
    })
  },
  changePathInfo(item){
    let iconPathInfo = {}
    switch(item.state){
      case '1':
        iconPathInfo.pathName = 'kanCha'
        iconPathInfo.iconPath = this.data.kanCha1
        return iconPathInfo
      case '2':
        iconPathInfo.pathName = 'shiGong'
        iconPathInfo.iconPath = this.data.shiGong1
        return iconPathInfo
      case '3':
        iconPathInfo.pathName = 'jiaoFu'
        iconPathInfo.iconPath = this.data.jiaoFu1
        return iconPathInfo
      case '4':
        iconPathInfo.pathName = 'guZhang'
        iconPathInfo.iconPath = this.data.guZhang1
        return iconPathInfo
      case '5':
        iconPathInfo.pathName = 'chaiChu'
        iconPathInfo.iconPath = this.data.chaiChu1
        return iconPathInfo

    }
  },
  /**
   * 
   * @param {站点详情} options 
   */
  itemDetail(e){
    console.log("页面传参",e);
    let item = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
    let packetId = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item.packetId));
    wx.navigateTo({
      url: `../toOrderDetails/toOrderDetails?info=${item}`,
    })
  },
  //信息筛选
  showRightPop(){
   
    console.log(this.data.showPop,'dfvdfvdf')
    let tagName = this.data.tagName
    tagName.forEach(item=>{
      item.typeCode=false
      
    })
    this.setData({
      showPop : !this.data.showPop,
      tagName ,
      // siteCondition 
    })
  },
  // 按标签搜索
  tagSearch(){
    
    // let tagName = this.data.tagName;
    // let tag = [];
    // tagName.forEach(item=>{
    
    //   if(item.typeCode){
        
    //     tag.push(item.valueId)
        
    //   }
      
      
    // })
    // let states = this.data.selectSiteCondition.valueId
    // this.siteList(tag.toString(),(states!=''&&states!="0")?states:'')
    
  
    // setTimeout(()=>{
     
    //   this.showRightPop();
    // },500)
    this.showRightPop();
  },
  clickSelectIndexType(e){
    this.setData({
      selectIndexType:e.currentTarget.dataset.type
    })
  },
  /**
   * 监听滚动
   * @param {*} options 
   */
  handletouchmove: function(event) {
    console.log('监听滑动') 
  },
 
  handletouchstart:function(event) {
    this.data.lastX = event.touches[0].pageX;
    this.data.lastY = event.touches[0].pageY;
  },
  handletouchend:function(event) {
    let currentY = event.changedTouches[0].pageY;
    let ty = currentY - this.data.lastY;
    if (ty < 0){
      if(!this.data.showSecondlevel){
        this.setData({
          showSecondlevel:true
        })
      }
    }
    else if (ty > 20) {
      console.log('尽力阿里',ty)
      if(this.data.showSecondlevel){
        this.setData({
          showSecondlevel:false
        })
        return
      }
      if(this.data.showloactionInfo){
        this.setData({
          showloactionInfo:false
        })
      }
    }
  },
  selectItemSwitch(e){
    let index = e.currentTarget.dataset.index;
    let switchList = this.data.switchList;
    switchList[index].value = switchList[index].value == 1 ? "0" : "1";
    let selectSwitchItem = e.currentTarget.dataset.item;
    this.setData({
      switchList,
      selectSwitchItem,
    });
    console.log("状态按钮传参", e.currentTarget.dataset)
    let params = {
      id: this.data.switchList[index].id,
      value: this.data.switchList[index].value,
    };
    lgRequest("modificationOfConstructionSchedule", params, {
      doSuccess: (r) => {
        console.log("修改成功", r)
      }
    })
  },
  resetTag(){
    let tagName = this.data.tagName;
    tagName.forEach(item=>
      item.typeCode = false)
    let OrderUrgency = this.data.OrderUrgency;
    OrderUrgency.forEach(r=>{
      r.isSelect = false
    })
    let orderType = this.data.orderType;
    orderType.forEach(r=>{
      r.isSelect = false
    })
    let overPeople = this.data.overPeople;
    overPeople.forEach(r=>{
      r.isSelect = false
    })
    this.siteList()
    this.setData({
      selectIndex:'',
      selectChIndex:'',
      isSelectSiteCondition:'j',
      tagName,
      OrderUrgency,
      orderType,
      overPeople

    })
    

  },
  /**
   * 巡查、联系人、记录
   * @param {*} options 
   */
  toOtherPage(e){
    let type = e.currentTarget.dataset.type
    let item = encodeURIComponent(JSON.stringify(this.data.clickItemPostion));
    let packetId = encodeURIComponent(JSON.stringify(this.data.clickItemPostion.packetId));
    switch(type){
      case '1':
        wx.navigateTo({
          url: '../minePage/freePatrol/freePatrol',
        })
        break;
      case '2':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?type=2&zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
      case '3':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?type=3&zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
      case '4':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
    }
  },
    // 获取标签列表
    getTagList(){
      let server = getApp().globalData.server
      let Authorization = getApp().globalData.Authorization
      wx.request({
        url: `${server}server/dictionaries/site_tag`,
        header : {
          Authorization
        },
        success:(r)=>{
          this.setData({
            tagName : r.data.data
          })
        }
    })
  },
  selectItemEncy(e){
    let ItemEncy = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let OrderUrgency = this.data.OrderUrgency
    
    // OrderUrgency.forEach(item=>{
    //   item.isSelect=false
    // })
    OrderUrgency[index].isSelect = !OrderUrgency[index].isSelect
    this.setData({
      OrderUrgency
    })
    let urgent = [];
    OrderUrgency.forEach(item=>{
      if(item.isSelect){
        urgent.push(item.valueId)
      }
    })
    urgent=urgent.toString()
    console.log(urgent)
    this.siteList('','',urgent)
  },
  selectItemType(e){
    let ItemEncy = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let orderType = this.data.orderType
    // orderType.forEach(item=>{
    //   item.isSelect = false
    // })
    orderType[index].isSelect = !orderType[index].isSelect
    this.setData({
      orderType
    })
    let type = [];
    orderType.forEach(item=>{
      if(item.isSelect){
        type.push(item.id)
      }
    })
    type=type.toString()
    console.log("111111111111111111",type)
    this.siteList('','','',type)
  },
  selectItemPeople(e){
    let ItemEncy = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let overPeople = this.data.overPeople
    overPeople[index].isSelect = !overPeople[index].isSelect
    this.setData({
      overPeople
    })
    let conductors = [];
    overPeople.forEach(item=>{
      if(item.isSelect){
        conductors.push(item.userId)
      }
    })
    conductors=conductors.toString()
    console.log("111111111111111111",conductors)
    this.siteList('','','','',conductors)
  },
    // 展示暂不处理
    showFailureBypass(e){
      console.log(e)
      this.data.params.wid=e.currentTarget.dataset.item.wid;
      this.setData({
        showFailureBypass:true
      })
  
    },
      // 关闭弹窗
  onClose(){

    let noProcessing = this.data.noProcessing;
    noProcessing.forEach(r=>{
      r.is=false
    })
    this.setData({
      showFailureBypass:false,
      noProcessing,
      params:{},
      remark:"",
      showOrderFlow:false,
      showOrderCompletion:false,
    })
  },
    // 获取暂不处理原因
    noProcessing(){
      let params = {
        code : "failure_bypass"
      }
      lgRequest("dictionaries",params,{
        doSuccess:r=>{
          console.log(r)
          this.setData({
            noProcessing:r.data
          })
        }
      })
    },
    // 暂不处理原因
    selectFailureBypass(e){
      let index = e.currentTarget.dataset.index;
      let item = e.currentTarget.dataset.item;
      let params = this.data.params;
      params.failureBypass=item.valueId;
      params.state=4;
      this.setData({
        params
      })
      
  
      console.log(e)
      let noProcessing =this.data.noProcessing;
      noProcessing[index].is=!noProcessing[index].is
      this.setData({
        noProcessing
      })
    },
    // 暂不处理说明
    getFailureBypassRemark(e){
      console.log(e.detail.value)
      this.data.params.remark=e.detail.value
      console.log(this.data.params.remark)
    },
    submitFailureBypass(){
      let params = this.data.params
      lgRequest("smbitQuestionPic",params,{
        doSuccess:r=>{
          console.log(r)
          // this.getOrderList();//获取工单列表
          this.onClose();
  
        }
      })
    },
      // 获取问题列表
  getOrderList(res){
    let params = {
      zId : res
    }
    lgRequest("dList",params,{
      doSuccess:(r)=>{
        console.log(r)
        let clickItem1 =r.data;
        clickItem1.forEach(res=>{
          
          // res.forEach(a=>{
            if(res.over){
              let arr = []
              arr = res.over.split(",")
              res.over = arr
              console.log(arr)
            }
          
          // })
        })
        this.setData({
          clickItem1
        })
      }
    })
  },
  showOrderFlow(e){
    this.data.params.wid = e.currentTarget.dataset.item.wid
    this.setData({
      showOrderFlow:true
    })
  },
  // 得得得得得的额
  overPeople(){
    let params = {
      code:"group"
    }
    lgRequest("userList",{},{
      doSuccess:r=>{
        console.log(r)
        let overPeople = r.data
        overPeople.forEach(item=>{
          item.value = item.userId;
          item.text = item.roleName;
        })
        this.setData({
           overPeople

        })
      }
    })
  },
  // 展示流转人
  showPeople(){
    this.setData({
      showPeople:true
    })
  },
  // 关闭流转人窗口
  onCloseC(){
    this.setData({
      showPeople:false
    })
  },
  // 选择流转人
  selectPeople(e){
    console.log(e)
    let selectPeople = e.currentTarget.dataset.item.nickName;
    this.data.params.conductor = e.currentTarget.dataset.item.userId;
    this.setData({
      selectPeople
    })
    this.onCloseC();
  },
  // 选择问题
  selectType(e){
    console.log(e)
    let isType = e.currentTarget.dataset.index;
    let typeCode = e.currentTarget.dataset.typeCode;

    this.setData({
      isType
    })
    
  },
  // 获取工单流转问题标签
  getProblemTag(){
    let params={
      code:"problem_type",
    }
    lgRequest("dictionaries",params,{
      doSuccess:r=>{
        console.log(r);
        this.setData({
          problemTag : r.data,
        })
      }
    })
  },
  // 选择工单流转问题
  selectproblemTag(e){
    
    console.log(e)
    let item = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let problemTag =this.data.problemTag;
    
    this.data.problemType.push(item.valueId)
    console.log(this.data.problemType)
    problemTag[index].is=!problemTag[index].is
    this.data.params.problemType = this.data.problemType.toString();

    this.setData({
      problemTag
    })
  },
  // 获取流转说明
  getOrderFlow(e){
    console.log(e.detail.value)
    this.data.params.mvremark = e.detail.value
  },
  // 提交工单流转信息
  submitOrderFlow(){
    this.data.params.dqGps = this.data.workList.gps;
    let params = this.data.params;
    lgRequest("submitOrderFlow",params,{
      doSuccess:r=>{
        console.log(r)
        this.getOrderList();//获取工单列表
        this.onClose();
      }
    })
    
  },
  showOrderCompletion(e){
    this.data.params.wid = e.currentTarget.dataset.item.wid
    this.setData({
      showOrderCompletion:true
    })
  },
  // 完成工单确定
  OrderCompletion(){
    this.data.params.zid = this.data.undoneInfoList.zid;
    this.data.params.dqGps = this.data.undoneInfoList.gps;
    this.data.params.conductor = this.data.undoneInfoList.conductor;
    this.data.params.state = 2;
    let params = this.data.params
    lgRequest("smbitQuestionPic",params,{
      doSuccess:r=>{
        console.log(r)
        this.getOrderList();//获取工单列表
        this.onClose();
      }
    })
  },
   // 上传相册
   smbitPic(e){
    let wid = e.currentTarget.dataset.item.wid;
    wx.chooseMedia({
      count: 9,
      mediaType: ['image'],
      sourceType: ['album'],
      success:(res)=> {
        console.log(res.tempFiles[0].tempFilePath)
        console.log(res.tempFiles[0].size)
        console.log(res)
        res.tempFiles.forEach(item=>{
          wx.uploadFile({
            url:"https://www.mengbaoonline.com:8182/common/upload",
            // url: "http://114.115.190.196:8082/common/upload",
            filePath: item.tempFilePath,
            name: "file",
            formData: {
              user: "test"
            },
            header: {
              Authorization: getApp().globalData.Authorization
            },
            success: (res) => {
              // 上传完成需要更新 fileList 
              let data = JSON.parse(res.data);
              console.log(data)
              wx.showToast({
                title: "上传成功！",
              });
              // if (res.code == 200) {
                let params = {
                  wid,
                  over: data.url,
                }
                lgRequest("smbitQuestionPic", params, {
                  doSuccess: (res) => {
                    // debugger
                    console.log('图片上传成功', res)
                    this.getOrderList(this.data.Mid)
                    
                  }
                })
              // }
  
            },
            fail(error) {
              wx.showToast({
                title: "上传失败，请稍后再试！",
              });
              console.log(error)
            },
          });
        })
       
      }
    })
    
  },
  // 拍照
  phonePic(e){
    console.log(e)
    let wid = e.currentTarget.dataset.item.wid;
    wx.chooseMedia({
      count: 9,  
      mediaType: ['image'],
      sourceType: ['camera'],
      success:(res) =>{
        console.log(res.tempFiles[0].tempFilePath)
        console.log(res.tempFiles[0].size)
        res.tempFiles.forEach(item=>{
          wx.uploadFile({
            url:"https://www.mengbaoonline.com:8182/common/upload",
            // url: "http://114.115.190.196:8082/common/upload",
            filePath: item.tempFilePath,
            name: "file",
            formData: {
              user: "test"
            },
            header: {
              Authorization: getApp().globalData.Authorization
            },
            success: (res) => {
              // 上传完成需要更新 fileList 
              let data = JSON.parse(res.data);
              console.log(data)
              wx.showToast({
                title: "上传成功！",
              });
              // if (res.code == 200) {
                let params = {
                  wid,
                  over: data.url,
                }
                lgRequest("smbitQuestionPic", params, {
                  doSuccess: (res) => {
                    // debugger
                    console.log('图片上传成功', res)
                    this.getOrderList(this.data.Mid)
                    
                  }
                })
              // }
  
            },
            fail(error) {
              wx.showToast({
                title: "上传失败，请稍后再试！",
              });
              console.log(error)
            },
          });
        })
        

      }
    })
    
  },
    // 跳转工单详情
    toOrderDetails(e){
      console.log("页面传参",e);
      let info = encodeURIComponent(JSON.stringify(this.data.undoneInfoList));
      wx.navigateTo({
        url: `../../minePage/toOrderDetails/toOrderDetails?info=${info}`,
      })
    },
    totransfer(e){
      // let info = e.currentTarget.dataset.item
      let info = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
      wx.navigateTo({
        url: `../transferRecord/transferRecord?info=${info}`,
        fail:err=>{
          console.log(err)
        }
      })
    },

  // 测试组件内部数据
//     zz(e){
//   console.log(e)
// },
//   ss(e){
//   console.log(e)
// },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.constructionProgress()
    let that = this
    this.fList()
    // this.siteList() //站点信息
    app.watch(this, {
      scale: function (newVal) {
        if(newVal<=11){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}1`
            item.iconPath = that.data[iconPath]
            item.width = 9,
            item.height = 9
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else if(11<newVal&&newVal<=13){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}2`
            item.iconPath = that.data[iconPath]
            item.width = 11,
            item.height = 13
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else if(13<newVal&&newVal<=16){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}3`
            item.iconPath = that.data[iconPath]
            item.width = 24.5,
            item.height = 31
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else {
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}3`
            item.iconPath = that.data[iconPath]
            item.width = 29.5,
            item.height = 38
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        }
      }
    })
    this.getTagList();//获取标签列表
    this.getSite();//获取站点状态列表
    this.getOrderUrgency();
    this.noProcessing();
    this.overPeople();
    this.getProblemTag();
    
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  onReady:function () {
    
    let that = this
    this.data.mapCtx = wx.createMapContext('myMap')
    this.data.mapCtx.getScale({
      success:function(res){
        that.setData({
          scale:res.scale
        })
      },
    })
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        console.log(res,'dfvd')
        const latitude = res.latitude
        const longitude = res.longitude
        that.setData({
          latitude: latitude,
          longitude: longitude
        })
      }
    })
 
  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.siteList();
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('fgbfgbfgb')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})